package databean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import databean.mydata;
import databean.ProductFund;
import databean.Affiance;

public class ProductBean {
	public ProductBean(){}
	
	public ArrayList<ProductFund> getProductFund(){
		ArrayList<ProductFund> arr = new ArrayList<ProductFund>();
		mydata db = new mydata();
		ResultSet rs = null;
		try {
			String sql = "select * from productfund";
			rs = db.myquery(sql);
			while(rs.next()){
				int productId = rs.getInt("productId");
				String productname = rs.getString("productname");
				double valuePer = rs.getDouble("valuePer");
				double valueAccumulate = rs.getDouble("valueAccumulate");
				double rateInThreeMonth = rs.getDouble("rateInThreeMonth");
				double rateInSixMonth = rs.getDouble("rateInSixMonth");
				double rateInOneYear = rs.getDouble("rateInOneYear");
				double rateFromFounded = rs.getDouble("rateFromFounded");
				
				ProductFund pf = new ProductFund(productId, productname,valuePer,valueAccumulate,rateInThreeMonth,
						rateInSixMonth,rateInOneYear,rateFromFounded);
				arr.add(pf);
			}
			System.out.println(arr.size());
			rs.close();
			db.closesql();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return arr;
	}
	
	public ArrayList<Affiance> getProductAffiance(){
		ArrayList<Affiance> arr = new ArrayList<Affiance>();
		mydata db = new mydata();
		ResultSet rs = null;
		try {
			String sql = "select * from affiance";
			rs = db.myquery(sql);
			while(rs.next()){
				String productName = rs.getString("productName");
				String company = rs.getString("company");
				String publishTime = rs.getString("publishTime");
				String term = rs.getString("term");
				int amount = rs.getInt("amount");
				int threshold = rs.getInt("threshold");
				String invest = rs.getString("invest");
				double rate = rs.getDouble("rate");
				String state = rs.getString("state");			
				Affiance aff = new Affiance(productName,company,publishTime,term,amount,threshold,invest,rate,state);
				arr.add(aff);
			}
			System.out.println(arr.size());
			rs.close();
			db.closesql();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return arr;
	}
}
